package com.whitewolf.gamer.controller;

import com.whitewolf.gamer.common.model.Result;
import com.whitewolf.gamer.entity.Carousel;
import com.whitewolf.gamer.entity.GameCategory;
import com.whitewolf.gamer.entity.Notice;
import com.whitewolf.gamer.service.GameService;
import com.whitewolf.gamer.vo.GamerRankingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游戏控制器
 */
@RestController
@RequestMapping("/api/v1/game")
public class GameController {

    @Autowired
    private GameService gameService;

    /**
     * 获取轮播图列表
     */
    @GetMapping("/carousels")
    public Result<List<Carousel>> getCarousels() {
        List<Carousel> carousels = gameService.getCarousels();
        return Result.success(carousels);
    }

    /**
     * 获取公告列表
     */
    @GetMapping("/notices")
    public Result<List<Notice>> getNotices() {
        List<Notice> notices = gameService.getNotices();
        return Result.success(notices);
    }

    /**
     * 获取游戏分类列表
     */
    @GetMapping("/categories")
    public Result<List<GameCategory>> getGameCategories() {
        List<GameCategory> categories = gameService.getGameCategories();
        return Result.success(categories);
    }

    /**
     * 获取打手排行榜
     */
    @GetMapping("/ranking")
    public Result<List<GamerRankingVO>> getGamerRanking(
            @RequestParam(required = false) Long categoryId) {
        List<GamerRankingVO> ranking;
        if (categoryId != null) {
            ranking = gameService.getGamerRankingByCategory(categoryId);
        } else {
            ranking = gameService.getGamerRanking();
        }
        return Result.success(ranking);
    }

    /**
     * 搜索游戏/打手
     */
    @GetMapping("/search")
    public Result<Void> search(@RequestParam String keyword) {
        // TODO: 实现搜索功能
        return Result.success();
    }
}